package org.jackysoft.struts2.business;

import java.io.ByteArrayInputStream;
import org.joda.time.DateTime;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.entity.ArmMonthlySemiManufacturedProductReporter;
import org.jackysoft.report.ReporterLifecycle;
import org.jackysoft.service.ArmMonthlySemiManufacturedReporterService;
import org.jackysoft.util.HttpUtil;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Namespace("/reporter/semi")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ArmMonthlySemiManufacturedProductReporterAction extends
		ReporterCRUDAction<ArmMonthlySemiManufacturedProductReporter> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7358343042394022160L;
	private ArmMonthlySemiManufacturedProductReporter bean;
    private ArmMonthlySemiManufacturedReporterService service;
    private boolean regenate=false;
	
	public String preselect() throws Exception {
		bean = service.prepareSelect(DateTime.now());
		return SUCCESS;
	}
	
	public String openoffice() throws Exception {				
		byte[] bs = service.getResearchBytes(bean.getId(),isRegenate());		
		setContentType(HttpUtil.extToMimeType("xls"));
		setContentLength(bs.length);
		setUpLoadFileName("product.xls");
		inputStream = new ByteArrayInputStream(bs);
		return STREAM;
	}
	
	public String savedoc() throws Exception {
		service.updateResearch(bean.getId());
		return "saveok";
	}
	
	public ArmMonthlySemiManufacturedReporterService getService() {
		return service;
	}

	@Resource
	public void setService(ArmMonthlySemiManufacturedReporterService service) {
		this.service = service;
	    this.setDataProvider(service);
	}


	public ArmMonthlySemiManufacturedProductReporter getBean() {
		return bean;
	}


	public void setBean(ArmMonthlySemiManufacturedProductReporter bean) {
		this.bean = bean;
	}

	public boolean isRegenate() {
		return regenate;
	}

	public void setRegenate(boolean regenate) {
		this.regenate = regenate;
	}



}
